package cn.itsource.pet.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDetail;
import cn.itsource.pet.mapper.PetDetailMapper;
import cn.itsource.pet.mapper.PetMapper;
import cn.itsource.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetDetailMapper detailMapper;
    @Autowired
    private PetMapper petMapper;

    @Override
    @Transactional
    public void save(Pet pet) {
        //和宠物关联的宠物详情
        super.save(pet);//返回新增数据的主键
        PetDetail detail = pet.getDetail();
        //设置关联属性
        detail.setPet_id(pet.getId());
        //保存详情
        detailMapper.save(detail);
    }

    @Override
    public void onSale(Long[] ids) {
        petMapper.onSale(ids);
    }

    @Override
    public Pet loadByIdOfFront(Long id) {
        return petMapper.loadByIdOfFront(id);
    }
}
